const timeRange = ["2024-07-01 00:00:00", "2024-08-31 23:45:00"];

const loader = require("./loader.js");
const dayjs = require("dayjs");
const isBetween = require("dayjs/plugin/isBetween");
dayjs.extend(isBetween);

main();

function main() {
  loader.loadData().then((res) => {
    const tags = res.payloads.key.split(":");
    const data = res.data;
    //
    let totalFlight = 0;
    let totalDepZUTF = 0;
    let totalArrZUTF = 0;
    let totalDepZUUU = 0;
    let totalArrZUUU = 0;
    let maxDepZUTF = 0;
    let maxArrZUTF = 0;
    let maxDepZUUU = 0;
    let maxArrZUUU = 0;
    let countDays = 0;
    let countHours = 0;
    let countRushHours = 0;
    let countNormalHours = 0;
    //
    for (let i = 0; i < data.length; i++) {
      let moment = dayjs(data[i].moment);
      if (moment.isBetween(timeRange[0], timeRange[1], "minute", "[]")) {
        if (i == 0 || !moment.isSame(data[i - 1].moment, "day")) {
          countDays++;
        }
        if (i == 0 || !moment.isSame(data[i - 1].moment, "hour")) {
          countHours++;
        }
        for (let j = 0; j < data[i].content.length; j++) {
          totalFlight += data[i].content[j];
        }
      }
    }
    console.log(`totalFlight: ${totalFlight}`);
    console.log(`countHours: ${countHours}`);
    console.log(`countDays: ${countDays}`);
    console.log(
      `averageFlightPerHour: ${Math.round(totalFlight / countHours)}`
    );
    console.log(`averageFlightPerDay: ${Math.round(totalFlight / countDays)}`);
  });
}

function arrangeData(data, tags) {
  for (let i = 0; i < data.length; i++) {
    let moment = dayjs(data[i].moment);
    if (
      moment.isBetween(timeRange[0], timeRange[1], "minute", "[]") &&
      moment.minute() == 0 &&
      i + 3 < data.length
    ) {
    }
  }
}
